<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="红冲业务" prop="redBusinessType">
      <el-input v-model="dataForm.redBusinessType" placeholder="红冲业务"></el-input>
    </el-form-item>
    <el-form-item label="产品ID" prop="productId">
      <el-input v-model="dataForm.productId" placeholder="产品ID"></el-input>
    </el-form-item>
    <el-form-item label="产品编号" prop="productNo">
      <el-input v-model="dataForm.productNo" placeholder="产品编号"></el-input>
    </el-form-item>
    <el-form-item label="订单ID" prop="orderDetailId">
      <el-input v-model="dataForm.orderDetailId" placeholder="订单ID"></el-input>
    </el-form-item>
    <el-form-item label="产品出库单" prop="productLeaveId">
      <el-input v-model="dataForm.productLeaveId" placeholder="产品出库单"></el-input>
    </el-form-item>
    <el-form-item label="客户ID" prop="clientId">
      <el-input v-model="dataForm.clientId" placeholder="客户ID"></el-input>
    </el-form-item>
    <el-form-item label="纸箱入库单" prop="boxAddId">
      <el-input v-model="dataForm.boxAddId" placeholder="纸箱入库单"></el-input>
    </el-form-item>
    <el-form-item label="纸箱厂ID" prop="boxFactoryId">
      <el-input v-model="dataForm.boxFactoryId" placeholder="纸箱厂ID"></el-input>
    </el-form-item>
    <el-form-item label="过磅记录单" prop="weighDetailInfoId">
      <el-input v-model="dataForm.weighDetailInfoId" placeholder="过磅记录单"></el-input>
    </el-form-item>
    <el-form-item label="供应商ID" prop="supplierId">
      <el-input v-model="dataForm.supplierId" placeholder="供应商ID"></el-input>
    </el-form-item>
    <el-form-item label="财务往来商品记录" prop="financeTransactionProductId">
      <el-input v-model="dataForm.financeTransactionProductId" placeholder="财务往来商品记录"></el-input>
    </el-form-item>
    <el-form-item label="财务往来原料记录" prop="financeTransactionIngredientId">
      <el-input v-model="dataForm.financeTransactionIngredientId" placeholder="财务往来原料记录"></el-input>
    </el-form-item>
    <el-form-item label="红冲类型 0冲增、1冲减" prop="reversalType">
      <el-input v-model="dataForm.reversalType" placeholder="红冲类型 0冲增、1冲减"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="totalPrice">
      <el-input v-model="dataForm.totalPrice" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="单价" prop="unitPrice">
      <el-input v-model="dataForm.unitPrice" placeholder="单价"></el-input>
    </el-form-item>
    <el-form-item label="数量" prop="reversalNumber">
      <el-input v-model="dataForm.reversalNumber" placeholder="数量"></el-input>
    </el-form-item>
    <el-form-item label="原因备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="原因备注"></el-input>
    </el-form-item>
    <el-form-item label="图片保存" prop="reversalImageUrl">
      <el-input v-model="dataForm.reversalImageUrl" placeholder="图片保存"></el-input>
    </el-form-item>
    <el-form-item label="红冲时间" prop="dayTime">
      <el-input v-model="dataForm.dayTime" placeholder="红冲时间"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="创建人员" prop="createUser">
      <el-input v-model="dataForm.createUser" placeholder="创建人员"></el-input>
    </el-form-item>
    <el-form-item label="创建者" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建者"></el-input>
    </el-form-item>
    <el-form-item label="更新者" prop="updateUesr">
      <el-input v-model="dataForm.updateUesr" placeholder="更新者"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          redBusinessType: '',
          productId: '',
          productNo: '',
          orderDetailId: '',
          productLeaveId: '',
          clientId: '',
          boxAddId: '',
          boxFactoryId: '',
          weighDetailInfoId: '',
          supplierId: '',
          financeTransactionProductId: '',
          financeTransactionIngredientId: '',
          reversalType: '',
          totalPrice: '',
          unitPrice: '',
          reversalNumber: '',
          remark: '',
          reversalImageUrl: '',
          dayTime: '',
          status: '',
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: ''
        },
        dataRule: {
          redBusinessType: [
            { required: true, message: '红冲业务不能为空', trigger: 'blur' }
          ],
          productId: [
            { required: true, message: '产品ID不能为空', trigger: 'blur' }
          ],
          productNo: [
            { required: true, message: '产品编号不能为空', trigger: 'blur' }
          ],
          orderDetailId: [
            { required: true, message: '订单ID不能为空', trigger: 'blur' }
          ],
          productLeaveId: [
            { required: true, message: '产品出库单不能为空', trigger: 'blur' }
          ],
          clientId: [
            { required: true, message: '客户ID不能为空', trigger: 'blur' }
          ],
          boxAddId: [
            { required: true, message: '纸箱入库单不能为空', trigger: 'blur' }
          ],
          boxFactoryId: [
            { required: true, message: '纸箱厂ID不能为空', trigger: 'blur' }
          ],
          weighDetailInfoId: [
            { required: true, message: '过磅记录单不能为空', trigger: 'blur' }
          ],
          supplierId: [
            { required: true, message: '供应商ID不能为空', trigger: 'blur' }
          ],
          financeTransactionProductId: [
            { required: true, message: '财务往来商品记录不能为空', trigger: 'blur' }
          ],
          financeTransactionIngredientId: [
            { required: true, message: '财务往来原料记录不能为空', trigger: 'blur' }
          ],
          reversalType: [
            { required: true, message: '红冲类型 0冲增、1冲减不能为空', trigger: 'blur' }
          ],
          totalPrice: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          unitPrice: [
            { required: true, message: '单价不能为空', trigger: 'blur' }
          ],
          reversalNumber: [
            { required: true, message: '数量不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '原因备注不能为空', trigger: 'blur' }
          ],
          reversalImageUrl: [
            { required: true, message: '图片保存不能为空', trigger: 'blur' }
          ],
          dayTime: [
            { required: true, message: '红冲时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          createUser: [
            { required: true, message: '创建人员不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          updateUesr: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/finance/financereversalrecords/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.redBusinessType = data.financeReversalRecords.redBusinessType
                this.dataForm.productId = data.financeReversalRecords.productId
                this.dataForm.productNo = data.financeReversalRecords.productNo
                this.dataForm.orderDetailId = data.financeReversalRecords.orderDetailId
                this.dataForm.productLeaveId = data.financeReversalRecords.productLeaveId
                this.dataForm.clientId = data.financeReversalRecords.clientId
                this.dataForm.boxAddId = data.financeReversalRecords.boxAddId
                this.dataForm.boxFactoryId = data.financeReversalRecords.boxFactoryId
                this.dataForm.weighDetailInfoId = data.financeReversalRecords.weighDetailInfoId
                this.dataForm.supplierId = data.financeReversalRecords.supplierId
                this.dataForm.financeTransactionProductId = data.financeReversalRecords.financeTransactionProductId
                this.dataForm.financeTransactionIngredientId = data.financeReversalRecords.financeTransactionIngredientId
                this.dataForm.reversalType = data.financeReversalRecords.reversalType
                this.dataForm.totalPrice = data.financeReversalRecords.totalPrice
                this.dataForm.unitPrice = data.financeReversalRecords.unitPrice
                this.dataForm.reversalNumber = data.financeReversalRecords.reversalNumber
                this.dataForm.remark = data.financeReversalRecords.remark
                this.dataForm.reversalImageUrl = data.financeReversalRecords.reversalImageUrl
                this.dataForm.dayTime = data.financeReversalRecords.dayTime
                this.dataForm.status = data.financeReversalRecords.status
                this.dataForm.createUser = data.financeReversalRecords.createUser
                this.dataForm.createTime = data.financeReversalRecords.createTime
                this.dataForm.updateUesr = data.financeReversalRecords.updateUesr
                this.dataForm.updateTime = data.financeReversalRecords.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/finance/financereversalrecords/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'redBusinessType': this.dataForm.redBusinessType,
                'productId': this.dataForm.productId,
                'productNo': this.dataForm.productNo,
                'orderDetailId': this.dataForm.orderDetailId,
                'productLeaveId': this.dataForm.productLeaveId,
                'clientId': this.dataForm.clientId,
                'boxAddId': this.dataForm.boxAddId,
                'boxFactoryId': this.dataForm.boxFactoryId,
                'weighDetailInfoId': this.dataForm.weighDetailInfoId,
                'supplierId': this.dataForm.supplierId,
                'financeTransactionProductId': this.dataForm.financeTransactionProductId,
                'financeTransactionIngredientId': this.dataForm.financeTransactionIngredientId,
                'reversalType': this.dataForm.reversalType,
                'totalPrice': this.dataForm.totalPrice,
                'unitPrice': this.dataForm.unitPrice,
                'reversalNumber': this.dataForm.reversalNumber,
                'remark': this.dataForm.remark,
                'reversalImageUrl': this.dataForm.reversalImageUrl,
                'dayTime': this.dataForm.dayTime,
                'status': this.dataForm.status,
                'createUser': this.dataForm.createUser,
                'createTime': this.dataForm.createTime,
                'updateUesr': this.dataForm.updateUesr,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
